package com.oceansoft.mobile.econsole.modules.message.entity;

import com.alibaba.fastjson.JSONObject;
import com.oceansoft.mobile.econsole.modules.message.util.Utils;

import java.util.Date;

public class PushMessage {

    private static final long serialVersionUID = 1L;
    private int id;
    private int sendno;
    private String app_key = "3553db0092103cd51829adf9";//苏州公安app的key不可更改
    private int receiver_type;
    private String receiver_value;
    private String verification_code;
    private int msg_type = 2;
    private String msg_content;
    private String send_description;
    private String platform = "android";
    private Date create_time;
    private int is_send = 0;    //0:未发送     1:已发送

    private int apns_production = 0;

    private int time_to_live = 86400;

    private String override_msg_id = "";

    public PushMessage() {
    }

    public PushMessage(int sendno, int receiver_type, String receiver_value, String msg_content, String send_description) {
        this.sendno = sendno;
        this.receiver_type = receiver_type;
        this.receiver_value = receiver_value;
        this.msg_content = msg_content;
        this.send_description = send_description;
        this.verification_code = getencry(sendno, receiver_type, receiver_value);
    }

    private String getencry(int sendno, int receive_type, String receiver_value) {
        return Utils.Md5(String.valueOf(sendno) + String.valueOf(receive_type) + receiver_value + "679ac78d02f66d86b6451062");
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getSendno() {
        return this.sendno;
    }

    public void setSendno(int sendno) {
        this.sendno = sendno;
    }

    public String getApp_key() {
        return this.app_key;
    }

    public void setApp_key(String app_key) {
        this.app_key = app_key;
    }

    public int getReceiver_type() {
        return this.receiver_type;
    }

    public void setReceiver_type(int receiver_type) {
        this.receiver_type = receiver_type;
    }

    public String getReceiver_value() {
        return this.receiver_value;
    }

    public void setReceiver_value(String receiver_value) {
        this.receiver_value = receiver_value;
    }

    public String getVerification_code() {
        return this.verification_code;
    }

    public void setVerification_code(String verification_code) {
        this.verification_code = verification_code;
    }

    public int getMsg_type() {
        return this.msg_type;
    }

    public void setMsg_type(int msg_type) {
        this.msg_type = msg_type;
    }

    public String getMsg_content() {
        return this.msg_content;
    }

    public void setMsg_content(String msg_content) {
        this.msg_content = msg_content;
    }

    public String getSend_description() {
        return this.send_description;
    }

    public void setSend_description(String send_description) {
        this.send_description = send_description;
    }

    public String getPlatform() {
        return this.platform;
    }

    public void setPlatform(String platform) {
        this.platform = platform;
    }

    public int getApns_production() {
        return this.apns_production;
    }

    public void setApns_production(int apns_production) {
        this.apns_production = apns_production;
    }

    public int getTime_to_live() {
        return this.time_to_live;
    }

    public void setTime_to_live(int time_to_live) {
        this.time_to_live = time_to_live;
    }

    public String getOverride_msg_id() {
        return this.override_msg_id;
    }

    public void setOverride_msg_id(String override_msg_id) {
        this.override_msg_id = override_msg_id;
    }

    public Date getCreate_time() {
        return create_time;
    }

    public void setCreate_time(Date create_time) {
        this.create_time = create_time;
    }

    public MessageContent getMsgContent() {
        return JSONObject.parseObject(getMsg_content(), MessageContent.class);
    }

    /**
     * @author huangxz
     *         消息针对人群
     */
    public enum PushType {
        BROADCAST(1), GROUP(2), ALIAS(3);

        private int code;

        PushType(int type) {
            this.code = type;
        }

        public static PushType lookUp(int code) {
            ContentType resultType = null;
            for (PushType type : values()) {
                if (type.code == code) {
                    return type;
                }
            }
            return BROADCAST;
        }

        public int getType() {
            return this.code;
        }
    }

    /**
     * @author huangxz
     *         消息类型
     */
    public enum ContentType {
        LATEST_NEWS("新闻通知", -3), UPDATE_INFO("升级信息", -2), SYSTEM_NOTI("系统通知", -1), CASE_PROCESS(
                "办件过程", 1), ANNOUNCEMENT("公示公告", 2);
        private String name;
        private int code;

        private ContentType(String name, int code) {
            this.name = name;
            this.code = code;
        }

        public static String getTitle(int code) {
            ContentType resultType = null;
            for (ContentType type : values()) {
                if (type.code == code) {
                    resultType = type;
                    break;
                }
            }
            return null != resultType ? resultType.name : "信息";
        }

        public static ContentType lookUp(int code) {
            ContentType resultType = null;
            for (ContentType type : values()) {
                if (type.code == code) {
                    return type;
                }
            }
            return SYSTEM_NOTI;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }
    }

    public int getIs_send() {
        return is_send;
    }

    public void setIs_send(int is_send) {
        this.is_send = is_send;
    }
}